<html>
    <head>
        <title>MIES-WORKFLOW - Organizaci&oacute;n - <?php echo $_REQUEST["txtNombre"];?></title>
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
        <SCRIPT type="text/JavaScript" src="Includes/Solofun_generales.js"></SCRIPT>
        <SCRIPT type="text/JavaScript" src="Includes/ajax.js"></SCRIPT>
        <SCRIPT type="text/JavaScript" src="PHPMailer/fun_generales.js"></SCRIPT>
        <link href="estilos/dhtmlxtoolbar_dhx_black.css" media="screen" rel="stylesheet" type="text/css"/>
        <link href="estilos/dhtmlxlayout.css" media="screen" rel="stylesheet" type="text/css"/>
        <link href="estilos/dhtmlxlayout_dhx_black.css" media="screen" rel="stylesheet" type="text/css"/>
        <link href="estilos/dhtmlxwindows.css" media="screen" rel="stylesheet" type="text/css"/>
        <link href="estilos/dhtmlxwindows_dhx_black.css" media="screen" rel="stylesheet" type="text/css"/>
        <link href="estilos/dhtmlxgrid.css" media="screen" rel="STYLESHEET" type="text/css"/>
        <link href="SoloStyles/Solostyles.css" rel="STYLESHEET" type="text/css"/>

        <script type="text/javascript" src="scripts/dhtmlxcommon.js"></script>
        <script type="text/javascript" src="scripts/dhtmlxtoolbar.js"></script>
        <script type="text/javascript" src="scripts/dhtmlxgrid.js"></script>
        <script type="text/javascript" src="scripts/ext/dhtmlxgrid_srnd.js"></script>
        <script type="text/javascript" src="scripts/dhtmlxgridcell.js"></script>
        <script type="text/javascript" src="scripts/dhtmlxwindows.js"></script>
        <script type="text/javascript" src="scripts/dhtmlxlayout.js"></script>
        <script type="text/javascript" src="scripts/dhtmlxcontainer.js"></script>
        <script type="text/javascript" src="scripts/shiftzoom.js"></script>
        <script type="text/javascript" src="scripts/photo_viewer.js"></script>
    </head>
    <body style="margin: 0" onResize="window.location.href = window.location.href;">

        <?php if($_REQUEST["total_paginas"] > 0) {
            $pag_actual = $_REQUEST["pag_actual"];
            $id_tdl_datos = $_REQUEST["id_tdl_datos"];
            $total_paginas = $_REQUEST["total_paginas"];
            ?>
        <!--<div id="cabecera">
                 <table cellpadding="0" cellspacing="0" style="width: 90%">
            <tr>
                <td><img src="SoloTemplates/SoloTemplate_LogoCabecera.png" style="height: 50px" alt=""/></td>
                <td style="text-align:center" class="SoloStyle_TituloPaginas">Im&aacute;genes de Organizaciones - <?php echo $_REQUEST["txtNombre"];?></td>
            </tr>
        </table>
        </div>-->
        
        <div id="documento_contenido" style="height: 100%; overflow: auto; background-color: #CEDADA">
        <!--<div id="documento_contenido" style="margin: 2px; overflow: auto;">-->
            <div id="index" style="display: none"></div>

            <table border="0" cellpadding="0" cellspacing="5" style="height: inherit" align="center">
                <tr>
                    <td style="background-color: #CEDADA; vertical-align: top;">
                        <img id="cache" alt="pix" src="images/spacer.gif" style="border: 0; width: 1px; height: 1px" />
                    </td>
                    <td valign="top" style="overflow:auto; height: 100%">
                        <div id="photo"></div>
                    </td>
                </tr>
            </table>
            <input type="hidden" id="img_id_tdl_datos" value="<?php echo $id_tdl_datos;?>"/>
            <div id="caption"></div>
            <!--<input type="hidden" id="img_pagina" value="1"/>-->
        </div>
        
        <script type="text/JavaScript">
            var gridSeparador;
            var obLayout = new dhtmlXLayoutObject(document.body, "1C", "dhx_black");
                obLayout.setEffect("resize", false);
                obLayout.cells("a").hideHeader();
                //obLayout.setAutoSize("a","a");
                //obLayout.cells("a").setHeight("40");
                obLayout.cells("a").fixSize(true, true);
                //obLayout.cells("a").attachObject("cabecera");

                obLayout.cells("a").attachObject("documento_contenido");
                //alert(document.body.clientHeight)
                document.getElementById("photo").setAttribute("style", "height: "+(document.body.clientHeight-40));
            var obToolbar = obLayout.cells("a").attachToolbar();
                obToolbar.setIconsPath("images/dhtmlx/imgs/");
                obToolbar.loadXML("organizaciones_Imagenes.php?accion=toolbarImagenes&id_tdl_datos=<?php echo $id_tdl_datos;?>&pag_actual=<?php echo $pag_actual;?>&total_paginas=<?php echo $total_paginas;?>");

                obToolbar.attachEvent("onClick", function(id){

                    if(id == "pdf"){
                        //window.open("sbn_AdministrarDocumentos.php?accion=exportarImagen&pagina_actual="+{/literal}{$pagina_actual}{literal}+"&id_tdl_datos="+id_tdl_datos, '_blank');

                        obLayout.dhxWins = new dhtmlXWindows();
                        obLayout.dhxWins.setImagePath("images/dhtmlx/dhxwins_dhx_black/");

                        win_export = obLayout.dhxWins.createWindow('ventana_export', 128, 158, 200, 100);
                        obLayout.dhxWins.setSkin("dhx_black");
                        obLayout.dhxWins.window('ventana_export').centerOnScreen();
                        //obLayout.dhxWins.window('ventana_separador').center();
                        obLayout.dhxWins.window('ventana_export').setModal(true);
                        win_export.setText("Exportar a PDF");

                        var str = "<table cellpadding=\"0\" cellspacing=\"0\">";
                        str += "<tr><td class=\"SoloStyle_Etiqueta\">P&aacute;ginas:</td><td><input type=\"text\" id=\"paginas\" name=\"paginas\"/></td></tr>";
                        str += "<tr><td style=\"text-align: center\"><input type=\"button\" align=\"absmiddle\" class=\"SoloStyle_Boton2\" value=\"Exportar\" onclick=\"exportarPDF();\"/></td>";
                        str += "<td style=\"texSoloStyle_Textot-align: center\"><input type=\"button\" align=\"absmiddle\" class=\"SoloStyle_Boton2\" value=\"Cancelar\" onclick=\"win_export.close();\"/></td></tr>";
                        win_export.attachHTMLString(str);
                    }else if(id == "imprimir"){
                        /* var img_tag = document.getElementById("mainImage");
                        img_tag.setAttribute("class", "impresion");
                        img_tag = document.getElementById("mainImage_img");
                        img_tag.setAttribute("class", "impresion");*/
                        var div = document.getElementById("img_impresion");
                        if(div == null){
                            div = document.createElement("div");
                            div.setAttribute("id", "img_impresion");
                            div.setAttribute("class", "impresion");
                            document.body.appendChild(div);
                        }//else

                        var img = document.createElement("img");
                        img.setAttribute("class", "impresion");
                        img.setAttribute("src", photos[glbCurrentPhoto-1]);

                        var img_tag = div.getElementsByTagName("img");

                        if(img_tag[0] == null){//alert("por aca");
                            div.appendChild(img);
                        }else{
                            //alert("por aca 1");
                            div.replaceChild(img, img_tag[0]);
                        }
                        window.print();
                        //alert("a imprimir")
                    }else if(id == "pagina_previa"){
                        pagPrevia();
                    }else if(id == "pagina_siguiente"){
                        pagSiguiente();
                    }else if(id == "rotar_izq"){
                        rotar("izquierda");
                    }else if(id == "rotar_der"){
                        rotar("derecha");
                    }else if(id == "panning"){
                        shiftzoom.add(document.getElementById("mainImage"));
                    }else if(id == "zoom_in"){
                        var OBJECT = shiftzoom.get(document.getElementById('mainImage'),'currentxyz');
                        var zoom_actual = OBJECT.z;
                        shiftzoom.zooming(document.getElementById('mainImage'), zoom_actual+10);
                    }else if(id == "zoom_out"){
                        var OBJECT = shiftzoom.get(document.getElementById('mainImage'),'currentxyz');
                        var zoom_actual = OBJECT.z;
                        shiftzoom.zooming(document.getElementById('mainImage'), zoom_actual-10);
                    }else if(id == "separador"){
                        obLayout.dhxWins = new dhtmlXWindows();
                        obLayout.dhxWins.setImagePath("images/dhtmlx/dhxwins_dhx_black/");

                        var win1 = obLayout.dhxWins.createWindow('ventana_separador', 28, 58, 500, 400);
                        obLayout.dhxWins.setSkin("dhx_black");
                        obLayout.dhxWins.window('ventana_separador').centerOnScreen();
                        //miLayout.dhxWins.window('ventana_separador').center();
                        //obLayout.dhxWins.window('ventana_separador').setModal(true);
                        win1.setText("Separadores Virtuales");

                        gridSeparador = win1.attachGrid();
                        gridSeparador.setSkin("sbdark");
                        gridSeparador.setImagePath("images/dhtmlx/");
                        gridSeparador.init();
                        gridSeparador.loadXML("organizaciones_Imagenes.php?accion=separador&id_tdl_datos="+<?php echo $id_tdl_datos;?>);
                        gridSeparador.attachEvent("onRowSelect", consultarImagenesSeparador);
                    }else if(id == "salir"){
                        window.close();
                    }
                });
            //obLayout.cells("a").attachURL("organizaciones_Imagenes.php?accion=", "ajax");


            var alertTimerId = 0;
            shiftzoom.defaultButtons    = false;
            photos = new Array();
            //indexSeparator = ' / ';
            //glbCurrentPhoto = {$pagina_actual};
            glbCurrentPhoto = <?php echo $pag_actual;?>;

            <?php for($i = 0; $i < $total_paginas; $i++){?>
            addPhoto("organizaciones_Imagenes.php?accion=mostrarImagen&id_tdl_datos=<?php echo $id_tdl_datos;?>&pagina=<?php echo $i+1;?>&time=<?php echo mktime();?>","");
            <?php }?>

            function activateTimer(funcname) {
                clearTimeout(alertTimerId);
                alertTimerId = setTimeout(funcname, 500);
            }

            function exportarPDF(){
                var paginas = document.getElementById("paginas").value;
                var bValido = true;

                if(paginas != ""){
                    var strPags = "";
                    var arrComas = paginas.split(",");
                    for(var i = 0; i < arrComas.length; i++){
                        var arrGuiones = arrComas[i].split("-");
                        if(arrGuiones.length > 1){
                            for(var j = arrGuiones[0]; j < arrGuiones[1]; j++)
                                strPags += j+",";
                        }else
                            strPags += arrGuiones[0]+",";
                    }
                    //remover la ultima coma
                    strPags = strPags.substr(0, strPags.length-1);
                    var arrPagsTotal = strPags.split(",");

                    for(var k = 0; k < arrPagsTotal.length; k++){
                        if(arrPagsTotal[k] > <?php echo $total_paginas;?>){
                            bValido = false;
                            break;
                        }
                    }

                    if(bValido)
                        window.open("organizaciones_Imagenes.php?accion=exportarImagen&paginas="+paginas+"&id_tdl_datos="+<?php echo $id_tdl_datos;?>, '_blank');
                }
            }

            function pagPrevia(){
                var pag_anterior = parseInt(obToolbar.getValue("pag_actual"))-1;
                obToolbar.setValue("pag_actual", pag_anterior);
                if(pag_anterior == 1){
                    obToolbar.disableItem("pagina_previa");
                }
                if(pag_anterior == <?php echo $total_paginas-1;?>){
                    obToolbar.enableItem("pagina_siguiente");
                }
                activateTimer('showPrevious()');
            }

            function pagSiguiente(){
                var pag_siguiente = parseInt(obToolbar.getValue("pag_actual"))+1;
                obToolbar.setValue("pag_actual", pag_siguiente);
                if(pag_siguiente == <?php echo $total_paginas;?>){
                    obToolbar.disableItem("pagina_siguiente");
                }
                if(pag_siguiente > 1){
                    obToolbar.enableItem("pagina_previa");
                }
                activateTimer('showNext()');
            }

            function rotar(sentido){
                if(sentido == "derecha"){
                    if(indice_rotacion == 3)
                        indice_rotacion = 0;
                    else indice_rotacion++;
                }else{
                    if(indice_rotacion == 0)
                        indice_rotacion = 3;
                    else if(indice_rotacion == -1)
                        indice_rotacion = 2;
                    else
                        indice_rotacion--;
                }

                var grados = arrRotacion[indice_rotacion];
                var id_tdl_datos = document.getElementById("img_id_tdl_datos").value;
                var original = photos[glbCurrentPhoto-1];
                var nuevo = "organizaciones_Imagenes.php?accion=rotarImagen&id_tdl_datos="+id_tdl_datos+"&pagina="+glbCurrentPhoto+"&grados="+grados;

                photos[glbCurrentPhoto-1] = nuevo;
                initPhoto();
                photos[glbCurrentPhoto-1] = original;
            }

            function consultarImagenesSeparador(id){
                indice_rotacion = 0;
                glbCurrentPhoto = gridSeparador.cells(id, 0).getValue();
                obToolbar.setValue("pag_actual", glbCurrentPhoto);

                if(glbCurrentPhoto > 1)
                    obToolbar.enableItem("pagina_previa");
                initPhoto();
            }

            var id_tdl_datos = document.getElementById("img_id_tdl_datos").value;

            obToolbar.attachEvent("onEnter", function(id, value){
                glbCurrentPhoto = value;
                if(value > 1)
                    obToolbar.enableItem("pagina_previa");
                //alert(value);
                //activateTimer('initPhoto()');
                initPhoto();
            });

            //window.setTimeout("initPhoto();", 500);
            initPhoto();

        </script>
            <?php }else { ?>
        <script type="text/javascript">
            alert(acentos("No se encontraron imagenes para mostrar"));
            window.close();
        </script>
            <?php }?>
    </body>
</html>
